package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据用户id和菜品id查询购物车
     * @param currentId
     * @param dishId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{currentId} and dish_id = #{dishId}")
    ShoppingCart queryByDishIdWithUserId(Long currentId, Long dishId);

    /**
     * 根据用户id和套餐id查询购物车
     * @param currentId
     * @param setmealId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{currentId} and setmeal_id = #{setmealId}")
    ShoppingCart queryBySetmealIdWithUserId(Long currentId, Long setmealId);

    void update(ShoppingCart shoppingCart);

    @Insert("insert into shopping_cart (name,user_id,dish_id,setmeal_id,dish_flavor,number,amount,image,create_time) " +
            "values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> queryByUserId(Long userId);

    ShoppingCart queryByDishIdOrSetmealIdWithUserId(Long userId, Long dishId, Long setmealId, String dishFlavor);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);

    @Delete("delete from shopping_cart where id = #{id}")
    void delete(Long id);
}
